#pragma once

#include <map>
#include <windows.h>
#include "Photoreceptor.h"
#include <sstream>

#ifdef __cplusplus
typedef struct tagPOINTEX : public tagPOINT
{
	tagPOINTEX() { x = 0; y = 0; }

	tagPOINTEX(LONG _x, LONG _y) { x = _x; y = _y; }

	bool operator < (const tagPOINTEX& right) const
	{
		return x < right.x ? true : ( x > right.x ? false : y < right.y);
	}
} POINTEX, *LPPOINTEX;
#else
typedef struct tagPOINT POINTEX, *LPPOINTEX;
#endif


class Retina
{
public:
	typedef std::map<POINTEX, Photoreceptor> map_type;

private:
	map_type m_mapRetina;

public:
	Retina(LONG x_cnt, LONG y_cnt);
	virtual ~Retina(void);

	const Photoreceptor& getPhotoreceptorByPoint(int x, int y) const
	{
		map_type::const_iterator iter = m_mapRetina.find( POINTEX( x, y ) );

		if (iter == m_mapRetina.end())
		{
			std::stringstream str;
			str << "point(" << x << ", " << y << ") out of range.";
			throw std::out_of_range(str.str());
		}

		return iter->second;
	}
};
